﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace HFK.DxFluentUI.Utility
{
  public class TypedList<T> : ArrayList, ITypedList
  {
    public TypedList()
    {
      PropertyDescriptorCollection coll = TypeDescriptor.GetProperties(typeof(T));
      m_list = new ArrayList(coll);
    }

    PropertyDescriptorCollection ITypedList.GetItemProperties(PropertyDescriptor[] items)
    {
      if (items != null)
      {
        //for simple databindings
        return TypeDescriptor.GetProperties(items[0].PropertyType);
      }
      return new PropertyDescriptorCollection(m_list.ToArray(typeof(PropertyDescriptor)) as PropertyDescriptor[]);
    }

    string ITypedList.GetListName(PropertyDescriptor[] items) 
    { 
      return ""; 
    }

    public void RegisterProperty(string childPath)
    {
      m_list.Add(new ChildPropertyDescriptor(typeof(T), childPath));
    }

    private ArrayList m_list;
  }
}
